<script setup>
import { dayjs } from "element-plus";
import { Clock } from "@element-plus/icons-vue";
import useComputedParams from "@/hooks/useComputedParams";

defineProps({
  list: {
    type: Array,
    default: () => []
  }
});

const date = useComputedParams(time => {
  return dayjs(time).format("YYYY-MM-DD");
});
const time = useComputedParams(time => {
  return dayjs(time).format("HH:mm:ss");
});
</script>

<template>
  <!--
TODO:组件不通用，可使用slot优化
-->
  <div class="time-line">
    <el-timeline :reverse="true">
      <el-timeline-item v-for="(item, index) in list" :key="index" color="#2991FF" size="large" :hollow="true">
        <!--    左侧时间    -->
        <div class="time">
          <div>
            <span class="year">{{ date(item.trackDatetime).value }}</span>
          </div>
          <div class="day">
            <el-icon><Clock /></el-icon>
            <span>{{ time(item.trackDatetime).value }}</span>
          </div>
        </div>
        <!--    右侧内容    -->
        <div class="ml10">
          <div class="list-title">{{ item.trackTypeName }}</div>
          <div class="list-desc">
            <div class="list-desc-content">{{ item.contentDesc }}</div>
            <div class="list-desc-images">
              <el-image
                :preview-src-list="[imgItem.url]"
                v-for="imgItem in item.crmFileVOList"
                :key="imgItem.url"
                :src="imgItem.url"
              ></el-image>
            </div>
            <div class="list-desc-name">{{ item.roleName }}</div>
          </div>
        </div>
      </el-timeline-item>
    </el-timeline>
  </div>
</template>

<style scoped lang="scss">
@use "@/assets/styles/mixin";
.time-line {
  margin-left: 117px;
}
.list-title {
  margin-bottom: 4px;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.9);
  line-height: 24px;
}
.list-desc {
  padding: 10px;
  box-sizing: border-box;
  background-color: #f2f3f5;
  border-radius: 4px;
  &-content {
    margin-bottom: 4px;
    font-size: 14px;
    color: #3d3d3d;
    line-height: 24px;
  }
  &-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    grid-gap: 10px;
    margin: 10px 0 20px;
    :deep(.el-image) {
      width: 100%;
      height: 80px;
      border-radius: 4px;
    }
  }
  &-name {
    font-size: 12px;
    color: #86909c;
    line-height: 24px;
  }
}
//左侧时间
.time {
  color: #409eff;
  position: absolute;
  left: -118px;
  top: 1px;
  .year {
    font-size: 18px;
    font-weight: 400;
    color: #20354a;
  }
  .day {
    @include mixin.flex-align;
    justify-content: flex-end;
    width: 100%;
    font-size: 14px;
    font-weight: 400;
    color: #596878;
    text-align: right;
    margin-top: 10px;
    span {
      margin-left: 4px;
    }
  }
}
</style>
